function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {
    $(".pass_info").submit(function (e) {
        e.preventDefault();

        //  修改密码
        var old_pw= $('#pw1').val(),
            new_pw=$('#pw2').val(),
            new_pw2=$('#pw3').val();
        if(!old_pw){
            alert('请输入原始密码')
            return
        }
        if(!new_pw){
            alert('请输入新密码')
            return
        }
        if(new_pw!=new_pw2){
            alert('确认密码错误')
            return
        }
        var params={
            'old_password':old_pw,
            'new_password':new_pw
        }
        $.ajax({
            url:'/user/pass_info',
            type:'POST',
            headers:{
                'X-CSRFToken':getCookie('csrf_token')
            },
            contentType:'application/json',
            data:JSON.stringify(params),
            success:function (resp) {
                if(resp.errno=='0'){
                    location.reload()
                }else{
                    alert(resp.errmsg)
                }
            }
        })

    })
})